<template>
  <div>
    <el-dialog
      title="编辑"
      :visible.sync="dialogVisible"
      width="600px"
      :close-on-click-modal="false"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="栏目code" prop="code" v-show="flag">
          <el-input v-model="form.code"></el-input>
        </el-form-item>
        <el-form-item :label="type == 1 ? '栏目名称' : '名称'" prop="name">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="英文名称" prop="name" v-show="type == 1">
          <el-input v-model="form.field4"></el-input>
        </el-form-item>
        <el-form-item label="地址" prop="field3" v-show="flag && type == 1">
          <el-input v-model="form.field3"></el-input>
        </el-form-item>
        <el-form-item label="二级标题" prop="field1" v-show="type == 1">
          <el-input v-model="form.field1"></el-input>
        </el-form-item>
        <el-form-item label="是否显示" prop="isShow">
          <el-switch
            v-model="form.isShow"
            active-value="0"
            inactive-value="1"
          ></el-switch>
        </el-form-item>
        <el-form-item
          label="是否显示在菜单栏"
          prop="field2"
          v-show="flag && type == 1"
        >
          <el-switch
            v-model="form.field2"
            active-value="0"
            inactive-value="1"
          ></el-switch>
        </el-form-item>
        <el-form-item label="排序" prop="orderBy">
          <el-input-number
            v-model="form.orderBy"
            :min="1"
            :max="1000"
            size="medium"
            label="排序"
          ></el-input-number>
        </el-form-item>
        <el-form-item label="描述" v-show="false">
          <el-input type="textarea" v-model="form.content"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button v-show="flag" type="success" @click="handleAdd('form')"
          >新 增</el-button
        >
        <el-button type="primary" @click="handleEdit('form')">保 存</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { cloneDeep, pick } from 'lodash'
export default {
  data() {
    return {
      dialogVisible: false,
      form: {
        code: '',
        content: '',
        field1: '', //二级标题
        field2: '0', //是否显示在菜单栏  0显示 1不显示
        field3: '', //地址
        field4: '', //栏目英文名称
        field5: '',
        field6: '',
        isShow: '0', //0-展示，1-不显示
        name: '',
        orderBy: 10,
        type: '1',
      },
      rules: {
        deName: [
          { required: true, message: '请输入栏目名称', trigger: 'blur' },
        ],
      },
    }
  },
  props: ['flag', 'type'],
  mounted() {
    this.$bus.$on('updataTbDictDetail', (v) => {
      if (v) {
        this.form = cloneDeep(v)
      }
      this.dialogVisible = true
    })
  },
  beforeDestroy() {
    this.$bus.$off('updataTbDictDetail')
  },
  methods: {
    async handleEdit() {
      this.form.type = this.type
      await this.$store.dispatch('updateSysColumnControl', this.form)
      this.$bus.$emit('getSysColumnControl')
      this.dialogVisible = false
    },
    async handleAdd() {
      this.form.type = this.type
      await this.$store.dispatch('addSysColumnControl', this.form)
      this.$bus.$emit('getSysColumnControl')
      this.dialogVisible = false
    },
  },
}
</script>
<style scoped lang="scss">
</style>